<?php

namespace App\Services\Passport;

use Illuminate\Auth\CreatesUserProviders;

class UserProvider
{
    use CreatesUserProviders;

    private $provider;
    private $app;

    public function __construct($app)
    {
        $this->app = $app;
    }

    public function retrieveByCredentials(array $credentials)
    {
        return $this->getProvider()->retrieveByCredentials($credentials);
    }

    public function syncByResponse(array $response)
    {
        $model = $this->getProvider()->createModel();

        unset($response[ $model->getKeyName() ]);

        return $model->create($response);
    }

    protected function getProvider()
    {
        if ( !$this->provider ){
            $this->provider = $this->createUserProvider('users');
        }

        return $this->provider;
    }
}